pragma Ada_2012;
with Ada.Streams;
use Ada.Streams;
package Storage_Streams is

   -- in memory stream 
   type Storage_Stream_Type is abstract new Root_Stream_Type with private;
   type Storage_Stream_Pointer is access all Storage_Stream_Type'Class;

   function Length (
      this : Storage_Stream_Type
      ) return Stream_Element_Count;
   -- return writen data length

   procedure Copy_From (
      this : in out Storage_Stream_Type;
      From : in out Root_Stream_Type'Class;
      Size : Stream_Element_Count
      );
   -- copy data from another stream

   procedure Copy_To (
      this : in out Storage_Stream_Type;
      To   : not null access Root_Stream_Type'Class;
      Size : Stream_Element_Count
      );

   procedure Clear (this : in out Storage_Stream_Type) 
   is abstract;
   -- with post => this.Length + this.Read_Position + this.Write_Position = 0; 

   procedure Reset_For_Read (this : in out Storage_Stream_Type) 
   is abstract;
   -- with post => this.Read_Position = (if this.Length = 0 then 0 else 1);

   procedure Reset_For_Write (this : in out Storage_Stream_Type) 
   is abstract;
   -- with post => this.Write_Position = (if this.Length = 0 then 0 else 1);

   function Read_Position (
      this : Storage_Stream_Type
      ) return Stream_Element_Offset
   is abstract;
   -- return cursor for reader 

   function Write_Position (
      this : Storage_Stream_Type
      ) return Stream_Element_Offset
   is abstract;
   -- return cursor for writer 

   procedure Set_Read_Position (
      this : in out Storage_Stream_Type;
      Position : Stream_Element_Offset
      )
   is abstract;
   -- set cursor for reader

   procedure Set_Write_Position (
      this : in out Storage_Stream_Type;
      Position : Stream_Element_Offset
      )
   is abstract;
   -- set cursor for writer

   procedure Fill (
      this : in out Storage_Stream_Type'Class;
      Byte : Stream_Element;
      Size : Stream_Element_Count
      );
   -- fill stream with specified byte
   -- Constraint_Error may occur if out of capacity

   procedure Fill (
      this : in out Storage_Stream_Type'Class;
      Bytes : Stream_Element_Array;
      Count : Stream_Element_Count
      );
   -- fill stream with specified pattern
   -- Constraint_Error may occur if out of capacity

   procedure Free (P : in out Storage_Stream_Pointer);

   Library_Version : constant := 0.1;
   -- http://code.google.com/p/storage_streams
   -- last modified : 2012-09-015

private

   type Storage_Stream_Type is abstract new Root_Stream_Type with record
      F_Length : Stream_Element_Count := 0;
   end record;

end Storage_Streams;
